//
//  YHMyMerchantScreenMenuView.m
//  YHApp
//
//  Created by -- on 2021/12/19.
//

#import "HAMerchantScreenPopView.h"
#import "HACanalItemMo.h"
#import "YWAlertView.h"
#import "HACanalItemMo.h"
#import "YWAlertView.h"
#import "HAPolicyListMo.h"
#import "HAChooseTabPopView.h"

@interface HAMerchantScreenPopView ()<UITextFieldDelegate>

/***/
@property (nonatomic, strong) UIScrollView *scrollView;
/***/
@property (nonatomic, assign) CGFloat scrollH;

@property (nonatomic, strong) UITextField *seachField;

/***/
@property (nonatomic, strong) UILabel *startTimeLabel;
/***/
@property (nonatomic, strong) UILabel *endTimeLabel;

/***/
@property (nonatomic, strong) NSMutableArray *typeList;
@property (nonatomic, strong) NSMutableArray *typeBtnList;

@property (nonatomic, strong) NSMutableArray *stateList;
@property (nonatomic, strong) NSMutableArray *stateBtnList;

/***/
@property (nonatomic, strong) UILabel *policyConLabel;
@property (nonatomic, strong) UILabel *termmodConLabel;
@property (nonatomic, strong) UILabel *canalConLabel;

@property (nonatomic,strong) id <YWAlertViewProtocol>dateAlert;
/***/
@property (nonatomic, assign) NSInteger timeType;

/***/
@property (nonatomic, assign) NSInteger typeIntteger;
/***/
@property (nonatomic, assign) NSInteger stateIntteger;

@end


@implementation HAMerchantScreenPopView

-(instancetype)init {
    if (self = [super init]) {
        
        [self.typeList addObject:@"直属商户"];
        [self.typeList addObject:@"团队商户"];
        
        [self.stateList addObjectsFromArray:@[@"审核中", @"已实名", @"实名未通", @"未实名"]];
    }
    return self;
    
}

-(void)seachBtnClick {
    [self sureButtonClick];
}

-(void)time1Click {
    self.timeType = 1;
    [self.dateAlert show];
}

-(void)time2Click {
    self.timeType = 2;
    [self.dateAlert show];
}

- (id<YWAlertViewProtocol>)dateAlert{
    if (!_dateAlert) {
        WS(weakSelf)
        _dateAlert = [YWAlertView alertViewWithTitle:@"请选择日期" preferredStyle:YWAlertViewStyleDatePicker2 footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertStyleShowYearMonthDay cancelButtonTitle:@"取消" sureButtonTitles:@"确定" handler:^(NSInteger buttonIndex, id  _Nullable value) {
            
            if (!value) {
                return;
            }
            if (weakSelf.timeType == 1) {
                weakSelf.startTimeLabel.text = value;
            }
            if (weakSelf.timeType == 2) {
                weakSelf.endTimeLabel.text = value;
            }

        }];
    }
    return _dateAlert;
}

-(void)buttonTypeClick:(UIButton *)button {
    for (UIButton *button in self.typeBtnList) {
        [button setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
        button.layer.borderColor = [UIColor colorWithHexString:@"#333333"].CGColor;
    }
    [button setTitleColor:[UIColor colorWithHexString:@"#FFC4AC"] forState:UIControlStateNormal];
    button.layer.borderColor = [UIColor colorWithHexString:@"#FFC4AC"].CGColor;
    self.typeIntteger = button.tag;
}

-(void)buttonStateClick:(UIButton *)button {
    for (UIButton *button in self.stateBtnList) {
        [button setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
        button.layer.borderColor = [UIColor colorWithHexString:@"#333333"].CGColor;
    }
    [button setTitleColor:[UIColor colorWithHexString:@"#FFC4AC"] forState:UIControlStateNormal];
    button.layer.borderColor = [UIColor colorWithHexString:@"#FFC4AC"].CGColor;
    self.stateIntteger = button.tag;
}

-(void)termmodViewClick {
    NSMutableArray *dicts = [NSMutableArray array];
    for (HACanalItemMo *mo in self.termmodLists) {
        [dicts addObject:@{@"color":@"#373737",@"title":mo.text?:@""}];
    }
    HAChooseTabPopView *menu = [[HAChooseTabPopView alloc]initWithDicts:dicts title:@"选择产品型号"];
    [menu show];
    menu.YHChooseTabMenuCellBlock = ^(NSString * _Nonnull title) {
        for (HACanalItemMo *mo in self.termmodLists) {
            if ([title isEqualToString:mo.text]) {
                mo.isSel = YES;
                self.termmodConLabel.text = mo.text;
            }else {
                mo.isSel = NO;
            }
        }
    };
}

-(void)canalViewClick {
    NSMutableArray *dicts = [NSMutableArray array];
    for (HACanalItemMo *mo in [HASingle single].canalItemArray) {
        [dicts addObject:@{@"color":@"#373737",@"title":mo.text?:@""}];
    }
    HAChooseTabPopView *menu = [[HAChooseTabPopView alloc]initWithDicts:dicts title:@"选择产品通道"];
    [menu show];
    menu.YHChooseTabMenuCellBlock = ^(NSString * _Nonnull title) {
        for (HACanalItemMo *mo in [HASingle single].canalItemArray) {
            if ([title isEqualToString:mo.text]) {
                mo.isSel = YES;
                self.canalConLabel.text = mo.text;
            }else {
                mo.isSel = NO;
            }
        }
    };
}

-(void)policyViewClick {

    NSMutableArray *dicts = [NSMutableArray array];
    for (HAPolicyListMo *mo in self.policyLists) {
        [dicts addObject:@{@"color":@"#373737",@"title":mo.name?:@""}];
    }
    HAChooseTabPopView *menu = [[HAChooseTabPopView alloc]initWithDicts:dicts title:@"选择政策"];
    [menu show];
    menu.YHChooseTabMenuCellBlock = ^(NSString * _Nonnull title) {
        for (HAPolicyListMo *mo in self.policyLists) {
            if ([title isEqualToString:mo.name]) {
                mo.isSel = YES;
                self.policyConLabel.text = mo.name;
            }else {
                mo.isSel = NO;
            }
        }
    };
}

-(void)resetButtonClick {
    self.seachField.text = @"";

    self.startTimeLabel.text = @"请选择(YYYY-MM-DD)";
    self.endTimeLabel.text = @"请选择(YYYY-MM-DD)";
    
    self.typeIntteger = -1;

    for (UIButton *button in self.typeBtnList) {
        [button setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
        button.layer.borderColor = [UIColor colorWithHexString:@"#333333"].CGColor;
    }
    
    self.stateIntteger = -1;
    for (UIButton *button in self.stateBtnList) {
        [button setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
        button.layer.borderColor = [UIColor colorWithHexString:@"#333333"].CGColor;
    }
    
    for (HACanalItemMo *mo in [HASingle single].canalItemArray) {
        mo.isSel = NO;
    }
    self.canalConLabel.text = @"请选择产品通道";
    
    for (HACanalItemMo *mo in self.termmodLists) {
        mo.isSel = NO;
    }
    self.termmodConLabel.text = @"请选择产品型号";

    for (HAPolicyListMo *mo in self.policyLists) {
        mo.isSel = NO;
    }
    self.policyConLabel.text = @"请选择政策";
    
}

-(void)sureButtonClick {
    [self dismiss];
    NSString *searchText = self.seachField.text ?: @"";

    NSString *start = @"";
    NSString *end = @"";
    if (![self.startTimeLabel.text isEqualToString:@"请选择(YYYY-MM-DD)"]) {
        start = self.startTimeLabel.text;
    }
    if (![self.endTimeLabel.text isEqualToString:@"请选择(YYYY-MM-DD)"]) {
        end = self.endTimeLabel.text;
    }
    
    NSString *typeText = @"";
    if (self.typeIntteger == 0) {
        typeText = @"1";
    }else if (self.typeIntteger == 1) {
        typeText = @"2";
    }
    
    NSString *stateText = @"";
    if (self.stateIntteger == 0) {
        stateText = @"0";
    }else if (self.stateIntteger == 1) {
        stateText = @"1";
    }else if (self.stateIntteger == 2) {
        stateText = @"2";
    }else if (self.stateIntteger == 3) {
        stateText = @"3";
    }

    if (self.HAMerchantScreenPopViewBlock) {
        self.HAMerchantScreenPopViewBlock(searchText, start, end, typeText, stateText);
    }
}

-(void)loadViews {
    
    self.frame = CGRectMake(0, 0, kUIScreen_w, kUIScreen_h);
    [self addSubview:self.backgroundView];
    
    CGFloat alertViewW = kUIScreen_w*0.85;
    CGFloat alertViewH = kUIScreen_h;
    CGFloat alertViewX = kUIScreen_w-alertViewW;
    CGFloat alertViewY = kUIScreen_h-alertViewH;
    self.alertView.frame = CGRectMake(alertViewX, alertViewY, alertViewW, alertViewH);
    [self addSubview: self.alertView];
    self.alertView.backgroundColor = [UIColor whiteColor];
    self.alertView.layer.cornerRadius = 0;
    self.alertView.layer.masksToBounds = YES;
    
    UIScrollView *scrollView = [[UIScrollView alloc]init];
    scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    self.scrollView = scrollView;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    [self.alertView addSubview:scrollView];
    scrollView.frame = CGRectMake(0, app_topH+44, alertViewW, kScreenHeight-app_topH-44-app_bottomH);
    
    UIView *contentView = [UIView ha_createView];
    [scrollView addSubview:contentView];

    UILabel *titLabel = [UILabel ha_NLabelWithFont:18 textColor:@"#333333" text:@"全部筛选" alignment:0];
    [contentView addSubview:titLabel];
    [titLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(20);
    }];
    
    CGFloat btnY = 28+50;
    
    UIView *lineView = [UIView ha_createView];
    lineView.backgroundColor = [UIColor khaBGColor];
    [contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(btnY);
        make.height.mas_offset(1);
    }];
    
    UIButton *seachBtn = [[UIButton alloc]init];
    [seachBtn setImage:[UIImage xl_cuttingImageWith:[UIImage imageNamed:@"yh_10"] toSize:CGSizeMake(22, 22)] forState:UIControlStateNormal];
    [seachBtn addTarget:self action:@selector(seachBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:seachBtn];
    [seachBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(lineView);
        make.bottom.mas_equalTo(lineView).offset(-4);
        make.width.mas_offset(32);
        make.height.mas_offset(32);
    }];

    UITextField *seachField = [[UITextField alloc]init];
    self.seachField = seachField;
    seachField.delegate = self;
    seachField.placeholder = @"请输入名称/编号/机具编号";
    seachField.font = [UIFont systemFontOfSize:18];
    [contentView addSubview:seachField];
    [seachField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(lineView);
        make.right.equalTo(seachBtn.mas_left).offset(-5);
        make.centerY.mas_equalTo(seachBtn);
        make.height.equalTo(@32);
    }];
    
    btnY += 20;

    
    UIView *line2View = [UIView ha_createView];
    line2View.backgroundColor = [UIColor khaBGColor];
    [contentView addSubview:line2View];
    [line2View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(btnY+40);
        make.height.mas_offset(1);
    }];
    
    UILabel *tit3Label = [UILabel ha_NLabelWithFont:18 textColor:@"#333333" text:@"开始时间" alignment:0];
    [contentView addSubview:tit3Label];
    [tit3Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(line2View.mas_top).offset(-12);
        make.left.mas_equalTo(20);
        make.width.mas_offset(78);
    }];
    
    UILabel *startTimeLabel = [UILabel ha_NLabelWithFont:16 textColor:@"#333333" text:@"请选择(YYYY-MM-DD)" alignment:0];
    self.startTimeLabel = startTimeLabel;
    startTimeLabel.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(time1Click)];
    [startTimeLabel addGestureRecognizer:tap1];
    [contentView addSubview:startTimeLabel];
    [startTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(tit3Label);
        make.left.mas_equalTo(tit3Label.mas_right).offset(15);
        make.height.mas_offset(28);
    }];
    
    
    UIView *line3View = [UIView ha_createView];
    line3View.backgroundColor = [UIColor khaBGColor];
    [contentView addSubview:line3View];
    [line3View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(btnY+40+50);
        make.height.mas_offset(1);
    }];
    
    UILabel *tit4Label = [UILabel ha_NLabelWithFont:18 textColor:@"#333333" text:@"结束时间" alignment:0];
    [contentView addSubview:tit4Label];
    [tit4Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(line3View.mas_top).offset(-8);
        make.left.mas_equalTo(20);
        make.width.mas_offset(78);
    }];
    
    UILabel *endTimeLabel = [UILabel ha_NLabelWithFont:16 textColor:@"#333333" text:@"请选择(YYYY-MM-DD)" alignment:0];
    self.endTimeLabel = endTimeLabel;
    endTimeLabel.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(time2Click)];
    [endTimeLabel addGestureRecognizer:tap2];
    [contentView addSubview:endTimeLabel];
    [endTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(tit4Label);
        make.left.mas_equalTo(tit4Label.mas_right).offset(15);
        make.height.mas_offset(28);
    }];
    
    btnY = btnY + 72;
    CGFloat btnX = 20;
    CGFloat btnH = 24;
    CGFloat space = 10;
    
    if (self.typeList.count > 0) {
        btnY += 48;
        UILabel *titLabel = [UILabel ha_NLabelWithFont:18 textColor:@"#333333" text:@"商户类型" alignment:0];
        [contentView addSubview:titLabel];
        [titLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(btnY);
            make.left.mas_equalTo(20);
            make.width.mas_offset(78);
        }];
        
        btnY += 32;
        btnX = 20;
        [self.typeBtnList removeAllObjects];
        for (int i = 0; i < self.typeList.count; i ++) {
            UIButton *button = [[UIButton alloc]init];
            [button setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
            button.layer.borderColor = [UIColor colorWithHexString:@"#333333"].CGColor;
            if (![NSString isEmptyString:self.type]) {
                if (i == [self.type intValue]-1) {
                    [button setTitleColor:[UIColor colorWithHexString:@"#FFC4AC"] forState:UIControlStateNormal];
                    button.layer.borderColor = [UIColor colorWithHexString:@"#FFC4AC"].CGColor;
                    self.typeIntteger = i;
                }
            }else {
                self.typeIntteger = -1;
            }
            [button setTitle:self.typeList[i] forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            button.tag= i;
            button.layer.cornerRadius = 8;
            button.layer.masksToBounds = YES;
            button.layer.borderWidth = 1;
            [button addTarget:self action:@selector(buttonTypeClick:) forControlEvents:UIControlEventTouchUpInside];
            [contentView addSubview:button];
            CGFloat btnW = [[button currentTitle] sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}].width+24;
            if (btnX + btnW + space > alertViewW-12) {
                btnY = btnY + btnH + 10;
                btnX = 20;
            }
            button.frame = CGRectMake(btnX, btnY, btnW, btnH);
            btnX = btnX + btnW + space;//下一个x
            [self.typeBtnList addObject:button];
        }
    }
    
    if (self.stateList.count > 0) {
        btnY += 48;
        UILabel *titLabel = [UILabel ha_NLabelWithFont:18 textColor:@"#333333" text:@"商户状态" alignment:0];
        [contentView addSubview:titLabel];
        [titLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(btnY);
            make.left.mas_equalTo(20);
            make.width.mas_offset(78);
        }];
        btnY += 32;
        btnX = 20;
        [self.stateBtnList removeAllObjects];
        for (int i = 0; i < self.stateList.count; i ++) {
            UIButton *button = [[UIButton alloc]init];
            [button setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
            button.layer.borderColor = [UIColor colorWithHexString:@"#333333"].CGColor;
            if (![NSString isEmptyString:self.state]) {
                if (i == [self.state intValue]) {
                    [button setTitleColor:[UIColor colorWithHexString:@"#FFC4AC"] forState:UIControlStateNormal];
                    button.layer.borderColor = [UIColor colorWithHexString:@"#FFC4AC"].CGColor;
                    self.stateIntteger = i;
                }
            }else {
                self.stateIntteger = -1;
            }
            [button setTitle:self.stateList[i] forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            button.tag= i;
            button.layer.cornerRadius = 8;
            button.layer.masksToBounds = YES;
            button.layer.borderWidth = 1;
            [button addTarget:self action:@selector(buttonStateClick:) forControlEvents:UIControlEventTouchUpInside];
            [contentView addSubview:button];
            CGFloat btnW = [[button currentTitle] sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}].width+24;
            if (btnX + btnW + space > alertViewW-12) {
                btnY = btnY + btnH + 10;
                btnX = 20;
            }
            button.frame = CGRectMake(btnX, btnY, btnW, btnH);
            btnX = btnX + btnW + space;//下一个x
            [self.stateBtnList addObject:button];
        }
    }
            
    
    if ([HASingle single].canalItemArray.count > 0) {
        btnY += 48;
        UIView *itemView = [[UIView alloc] init];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(canalViewClick)];
        [itemView addGestureRecognizer:tap];
        [contentView addSubview:itemView];
        [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.right.mas_equalTo(-5);
            make.top.mas_equalTo(btnY);
            make.height.mas_offset(44);
        }];
        
        UIView *itemlineView = [UIView ha_createView];
        itemlineView.backgroundColor = [UIColor khaBGColor];
        [itemView addSubview:itemlineView];
        [itemlineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.height.mas_offset(1);
        }];
        
        UIImageView *itemRImgV = [UIImageView ha_createImageView];
        itemRImgV.image = [UIImage imageNamed:@"ic_cell_more"];
        [itemView addSubview:itemRImgV];
        [itemRImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_offset(5);
            make.height.mas_offset(10);
            make.centerY.mas_equalTo(0);
            make.right.mas_equalTo(-20);
        }];
        
        UILabel *itemtitLabel = [UILabel ha_NLabelWithFont:14 textColor:@"#333333" text:@"产品通道" alignment:0];
        [itemView addSubview:itemtitLabel];
        [itemtitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(0);
            make.left.mas_equalTo(0);
            make.width.mas_offset(72);
        }];
        
        UILabel *itemConLabel = [UILabel ha_NLabelWithFont:12 textColor:@"#666666" text:@"请选择产品通道" alignment:2];
        self.canalConLabel = itemConLabel;
        [itemView addSubview:itemConLabel];
        [itemConLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(0);
            make.right.mas_equalTo(itemRImgV.mas_left).offset(-5);
            make.left.equalTo(itemtitLabel.mas_right);
        }];
        
        for (HACanalItemMo *mo in [HASingle single].canalItemArray) {
            if (mo.isSel) {
                self.canalConLabel.text = mo.text;
                break;
            }
        }
    }

    
    if (self.termmodLists.count > 0) {
        btnY += 48;
        UIView *itemView = [[UIView alloc] init];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(termmodViewClick)];
        [itemView addGestureRecognizer:tap];
        [contentView addSubview:itemView];
        [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.right.mas_equalTo(-5);
            make.top.mas_equalTo(btnY);
            make.height.mas_offset(44);
        }];
        
        UIView *itemlineView = [UIView ha_createView];
        itemlineView.backgroundColor = [UIColor khaBGColor];
        [itemView addSubview:itemlineView];
        [itemlineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.height.mas_offset(1);
        }];
        
        UIImageView *itemRImgV = [UIImageView ha_createImageView];
        itemRImgV.image = [UIImage imageNamed:@"ic_cell_more"];
        [itemView addSubview:itemRImgV];
        [itemRImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_offset(5);
            make.height.mas_offset(10);
            make.centerY.mas_equalTo(0);
            make.right.mas_equalTo(-20);
        }];
        
        UILabel *itemtitLabel = [UILabel ha_NLabelWithFont:14 textColor:@"#333333" text:@"产品型号" alignment:0];
        [itemView addSubview:itemtitLabel];
        [itemtitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(0);
            make.left.mas_equalTo(0);
            make.width.mas_offset(72);
        }];
        
        UILabel *itemConLabel = [UILabel ha_NLabelWithFont:12 textColor:@"#666666" text:@"请选择产品型号" alignment:2];
        self.termmodConLabel = itemConLabel;
        [itemView addSubview:itemConLabel];
        [itemConLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(0);
            make.right.mas_equalTo(itemRImgV.mas_left).offset(-5);
            make.left.equalTo(itemtitLabel.mas_right);
        }];
        
        for (HACanalItemMo *mo in self.termmodLists) {
            if (mo.isSel) {
                self.termmodConLabel.text = mo.text;
                break;
            }
        }
    }
    
    if (self.policyLists.count > 0) {
        btnY += 48;
        UIView *policyView = [[UIView alloc] init];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(policyViewClick)];
        [policyView addGestureRecognizer:tap];
        [contentView addSubview:policyView];
        [policyView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.right.mas_equalTo(-5);
            make.top.mas_equalTo(btnY);
            make.height.mas_offset(44);
        }];
        
        UIView *policylineView = [UIView ha_createView];
        policylineView.backgroundColor = [UIColor khaBGColor];
        [policyView addSubview:policylineView];
        [policylineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.height.mas_offset(1);
        }];
        
        UIImageView *policyRImgV = [UIImageView ha_createImageView];
        policyRImgV.image = [UIImage imageNamed:@"ic_cell_more"];
        [policyView addSubview:policyRImgV];
        [policyRImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_offset(5);
            make.height.mas_offset(10);
            make.centerY.mas_equalTo(0);
            make.right.mas_equalTo(-20);
        }];
        
        UILabel *policytitLabel = [UILabel ha_NLabelWithFont:14 textColor:@"#333333" text:@"选择政策" alignment:0];
        [policyView addSubview:policytitLabel];
        [policytitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(0);
            make.left.mas_equalTo(0);
            make.width.mas_offset(72);
        }];
        
        UILabel *policyConLabel = [UILabel ha_NLabelWithFont:12 textColor:@"#666666" text:@"请选择政策" alignment:2];
        self.policyConLabel = policyConLabel;
        [policyView addSubview:policyConLabel];
        [policyConLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(0);
            make.right.mas_equalTo(policyRImgV.mas_left).offset(-5);
            make.left.equalTo(policytitLabel.mas_right);
        }];
        
        for (HAPolicyListMo *mo in self.policyLists) {
            if (mo.isSel) {
                self.policyConLabel.text = mo.name;
                break;
            }
        }
    }
    
    UIButton *resetButton = [[UIButton alloc]init];
    [resetButton setTitle:@"重置" forState:UIControlStateNormal];
    [resetButton setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
    resetButton.titleLabel.font = [UIFont systemFontOfSize:18];
    resetButton.layer.cornerRadius = 2;
    resetButton.layer.masksToBounds = YES;
    resetButton.layer.borderWidth = 1;
    resetButton.layer.borderColor = [UIColor colorWithHexString:@"#333333"].CGColor;
    [resetButton addTarget:self action:@selector(resetButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:resetButton];
    [resetButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_offset(44);
        make.width.mas_offset(120);
        make.top.mas_equalTo(btnY+88);
        make.centerX.mas_equalTo(-70);
    }];
    
    UIButton *sureButton = [[UIButton alloc]init];
    [sureButton setTitle:@"确定" forState:UIControlStateNormal];
    [sureButton setTitleColor:[UIColor colorWithHexString:@"#ffffff"] forState:UIControlStateNormal];
    sureButton.titleLabel.font = [UIFont systemFontOfSize:18];
    sureButton.layer.cornerRadius = 2;
    sureButton.layer.masksToBounds = YES;
    sureButton.layer.borderWidth = 1;
    sureButton.layer.borderColor = [UIColor colorWithHexString:@"#333333"].CGColor;
    sureButton.backgroundColor = [UIColor colorWithHexString:@"#333333"];
    [sureButton addTarget:self action:@selector(sureButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:sureButton];
    [sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_offset(44);
        make.width.mas_offset(120);
        make.top.mas_equalTo(btnY+88);
        make.centerX.mas_equalTo(70);
    }];
    
    if (![NSString isEmptyString:self.start]) {
        self.startTimeLabel.text = self.start;
    }
    if (![NSString isEmptyString:self.end]) {
        self.endTimeLabel.text = self.end;
    }
    self.seachField.text = self.keyword;
    
    self.scrollH = btnY+88+44+40;
    
    contentView.frame = CGRectMake(0, 0, alertViewW, self.scrollH);
}




- (NSMutableArray *)typeList
{
    if (!_typeList) {
        _typeList = [NSMutableArray array];
        
    }
    return _typeList;
}

- (NSMutableArray *)typeBtnList
{
    if (!_typeBtnList) {
        _typeBtnList = [NSMutableArray array];
        
    }
    return _typeBtnList;
}

- (NSMutableArray *)stateList
{
    if (!_stateList) {
        _stateList = [NSMutableArray array];
        
    }
    return _stateList;
}

- (NSMutableArray *)stateBtnList
{
    if (!_stateBtnList) {
        _stateBtnList = [NSMutableArray array];
    }
    return _stateBtnList;
}


-(void)show {
    
    UIWindow *keyWindow =  [[[UIApplication sharedApplication] windows] objectAtIndex:0];
    
    [keyWindow addSubview:self];
    CGRect rect = self.alertView.frame;
    rect.origin.x = kUIScreen_w;
    self.alertView.frame = rect;
    [UIView animateWithDuration:0.3 animations:^{
        CGRect rect = self.alertView.frame;
        rect.origin.x = kUIScreen_w-kUIScreen_w*0.85;
        self.alertView.frame = rect;
    }completion:^(BOOL finished) {
        self.scrollView.contentSize = CGSizeMake(0, self.scrollH);
    }];
}
-(void)dismiss {
    [UIView animateWithDuration:0.25 animations:^{
        CGRect rect = self.alertView.frame;
        rect.origin.x = kUIScreen_w;
        self.alertView.frame = rect;
        self.backgroundView.alpha = 0;
    } completion:^(BOOL finished) {
        for (UIView *view in self.subviews) {
            [view removeFromSuperview];
        }
        [self removeFromSuperview];
    }];
}

@end
